package com.inspur.sc.springboot.service.impl;

import com.inspur.sc.springboot.dao.SysPermissionDao;
import com.inspur.sc.springboot.entity.SysPermission;
import com.inspur.sc.springboot.service.SysPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Slf4j
public class SysPermissionServiceImpl implements SysPermissionService {

    @Autowired
    private SysPermissionDao permissionDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SysPermission permission) {
        try {
            permissionDao.save(permission);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    @Override
    public SysPermission findById(Integer id) {
        return permissionDao.findById(id).get();
    }

    @Override
    public List<SysPermission> findAll() {
        return permissionDao.findAll();
    }

    @Override
    public List<SysPermission> findByGroupId(Integer groupId) {
        return permissionDao.findByGroupId(groupId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Integer id) {
        try {
            permissionDao.deleteById(id);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }
}
